﻿@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index.cshtml";
}

<div class="topPanel">
    <div class="toolbar">
        <div class="btn-group">
            <a class="btn btn-primary" onclick="$.reload()"><span class="glyphicon glyphicon-refresh"></span></a>
        </div>
    </div>
    <div class="search">
        <table>
            <tr>
                <td>
                    <div class="input-group">
                        <input id="txt_keyword" type="text" class="form-control form-control-focus" placeholder="请输入卡号/住院号" style="width: 200px;">
                    </div>
                </td>
                <td style="padding-left:12px;">
                    <div class="btn-group" id="btnKeywordTypeGourp" style="margin-top:0;">
                        <button type="button" data-keywordtype="kh" class="btn active btn-restore">&nbsp;卡&nbsp;&nbsp;号&nbsp;</button>
                        <button type="button" data-keywordtype="zyh" class="btn btn-default">住院号</button>
                    </div>
                </td>
            </tr>
        </table>
    </div>
</div>

<div style="float:left;width:75%;">

    <div class="rows" style="margin-bottom: 1%;" id="divPatHospitalizationSettBasicInfo">
        <div class="panel panel-default" style="margin-top:10px; margin-bottom:0;">
            <div class="panel-heading navb-bg">
                住院病人信息
            </div>
            <table class="form" style="width:96%;">
                <tr>
                    <td class="formTitle">卡号：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="kh" value="" />
                    </td>
                    <td class="formTitle">住院号：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="zyh" value="" />
                    </td>
                    <td class="formTitle">病历号：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="blh" value="" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">姓名：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="xm" value="" />
                    </td>
                    <td class="formTitle">性别：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="xb" value="" />
                    </td>
                    <td class="formTitle">住院科别：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="ksmc" value="" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">患者类型：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" id="brxzmc" value="" />
                    </td>
                    <td class="formTitle">预交金：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="zhyjj" />
                    </td>
                    <td class="formTitle">医保证号：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="pzh" />
                    </td>
                </tr>
                <tr>
                    <td class="formTitle">入院日期：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="ryrq" />
                    </td>
                    <td class="formTitle">出院日期：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="cyrq" />
                    </td>
                </tr>
            </table>
        </div>
    </div>

    <div class="rows" style="margin-bottom: 1%;" id="divPatHospitalizationSettFeeInfo">
        <div class="panel panel-default" style="margin-bottom:0;">
            <div class="panel-heading navb-bg">
                结算信息
            </div>
            <table class="form" style="width:96%;">
                <tr>
                    <td class="formTitle">结算类型：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtSettType" />
                    </td>
                    <td class="formTitle">结算金额：</td>
                    <td class="formValue">
                        <input class="form-control" disabled readonly="readonly" type="text" value="" id="txtSettJSJE" />
                    </td>
                    <td class="formTitle"></td>
                    <td class="formValue"></td>
                </tr>
            </table>
        </div>
    </div>

    <div class="rows" style="margin-bottom: 1%;" id="divPatHospitalizationChargeListInfo">
        <table id="chargeGridList"></table>
    </div>

</div>


<div class="rows" style="margin-top:0.5%;float:left;width:24%;margin-left:1%;">
    <table id="dlFeeGridList"></table>
</div>
@Html.Partial("_BottomButtonsView", new Newtouch.HIS.Web.Core.Models.BottomButtonViewModel()
{
    ShowKeyList = new int[] { 4, 8 }
})

<script type="text/javascript">
    $('#btnKeywordTypeGourp').on('click', '.btn', function () {
        if (!$(this).hasClass('active')) {
            $(this).siblings('.btn').removeClass('btn-restore').removeClass('active').addClass('btn-default');
            $(this).removeClass('btn-default').addClass('btn-restore active');
        }
    });

    var txt_keyword = document.getElementById('txt_keyword');
    txt_keyword.addEventListener('keydown', function (event) {
        event = event || window.event;
        if (isLoadingIIII) {
            stopDefault(event); //数据加载过程中，阻止默认行为
            return false;
        }
        if (event.keyCode == 13) {
            ajaxLoadDataResult();
        }
    });

    //ajaxLoadResult
    var isLoadingIIII = false;  //是否正在从后台加载数据
    function ajaxLoadDataResult() {
        if (!isLoadingIIII) {
            isLoadingIIII = true;
            var keyword = $.trim($("#txt_keyword").val());
            if (keyword == '') {
                isLoadingIIII = false;
                return false;
            }
            $.loading(true, "正在请求数据...");
            var zyh = null;
            var kh = null;
            if ($('#btnKeywordTypeGourp .btn.active').attr('data-keywordtype') == 'kh') {
                kh = keyword;
            }
            else {
                zyh = keyword;
            }
            $.najax({
                type: "POST",
                url: "/HospitalizationManage/Settlement/GetStatusDetail",
                data: { zyh: zyh, kh: kh },
                dataType: "json",
                success: function (ajaxresp) {
                    //住院病人基本信息
                    $('#divPatHospitalizationSettBasicInfo').formSerialize(ajaxresp.data.HospSettPatInfo);
                    $("#xb").val($.getGender(ajaxresp.data.HospSettPatInfo.xb));
                    $("#ryrq").val((ajaxresp.data.HospSettPatInfo.ryrq && ajaxresp.data.HospSettPatInfo.ryrq.length >= 10 ? ajaxresp.data.HospSettPatInfo.ryrq.substring(0, 10) : ""));
                    $("#cyrq").val((ajaxresp.data.HospSettPatInfo.cyrq && ajaxresp.data.HospSettPatInfo.cyrq.length >= 10 ? ajaxresp.data.HospSettPatInfo.cyrq.substring(0, 10) : ""));
                    $('#zhyjj').val(ajaxresp.data.zhyjj.toFixed(2));
                    //患者交款历史
                    for (i = 0; i < ajaxresp.data.ChargeList.length; i++) {
                        ajaxresp.data.ChargeList[i].zyh = ajaxresp.data.HospSettPatInfo.zyh;
                        ajaxresp.data.ChargeList[i].xm = ajaxresp.data.HospSettPatInfo.xm;
                    }
                    $('#chargeGridList').newtouchLocalDataGrid(null, ajaxresp.data.ChargeList);
                    //票据信息
                    $('#dlFeeGridList').newtouchLocalDataGrid(null, ajaxresp.data.DLFeeList);
                    //结算信息
                    $('#txtSettType').val('出院结算');
                    $('#txtSettJSJE').val(ajaxresp.data.jsje.toFixed(2));
                },
                errorCallback: function (data) {
                    funcDoPageClear();
                },
                complete: function () {
                    isLoadingIIII = false;
                    $.loading(false);
                }
            });
        }
    }

    window.newtouch_globalconfig.f4opions = {
        container: "#divPatHospitalizationSettBasicInfo, #divPatHospitalizationSettFeeInfo"
    };

    //患者交款记录 jGrid声明
    $('#chargeGridList').newtouchLocalDataGrid({
        height: 100,
        unwritten: false,
        sortable: false,
        caption: "患者交款历史",
        colModel: [
            { label: '住院号', name: 'zyh', width: 100, align: 'left' },
            { label: '患者姓名', name: 'xm', width: 100, align: 'left' },
            {
                label: '交款金额', name: 'szje', width: 100, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "0.00";
                }
            },
            { label: '单据号', name: 'pzh', width: 100, align: 'left' },
            {
                label: '交款日期', name: 'CreateTime', width: 100, align: 'left', formatter: function (cellvalue) {
                    return cellvalue && cellvalue.length >= 10 ? cellvalue.substring(0, 10) : ""
                }
            },
            { label: '交款方式', name: 'xjzffsmc', width: 100 }
        ]
    });

    //患者交款记录 jGrid声明
    $('#dlFeeGridList').newtouchLocalDataGrid({
        height: 240,
        unwritten: false,
        sortable: false,
        caption: "票据信息",
        colModel: [
            { label: '项目名称', name: 'dlmc', width: 60, align: 'left' },
            {
                label: '总金额', name: 'jsje', width: 50, align: 'left', formatter: function (cellvalue) {
                    return cellvalue ? cellvalue.toFixed(2) : "";
                }
            }
        ]
    });

    //清除操作
    var funcDoPageClear = function () {
        newtouch_globalevent_f4();
    };

    function newtouch_event_f4() {
        $('#chargeGridList').jqGrid("clearGridData");   //清除所有行
        $('#dlFeeGridList').jqGrid("clearGridData");
    }

    //结算
    function newtouch_event_f8() {
        var zyh = $.trim($('#zyh').val());
        var jsje = $.trim($('#txtSettJSJE').val());
        var cyrq = $.trim($('#cyrq').val());
        var url = "/HospitalizationManage/Settlement/SettPreview?zyh=" + zyh + "&expectedjsje=" + jsje + "&expectedcyrq=" + cyrq + "&r=" + Math.random();
        if (zyh && jsje) {
            $.modalOpen({
                id: "FormShowSett",
                title: "结算",
                url: url,
                width: "670px",
                height: "490px",
                callBack: function (iframeId) {
                    top.frames[iframeId].submitSett();
                }
            });
        }
    }

    function showSettSuccessDialog(yingshoukuan, ssk, srce, zhaoling) {
        var url = "/HospitalizationManage/Settlement/SettSuccessDialog?yingshoukuan=" + yingshoukuan
            + "&ssk=" + ssk
            + "&srce=" + srce
            + "&zhaoling=" + zhaoling;
        $.modalOpen({
            id: "FormShowSettSuccessDialog",
            title: "结算成功",
            url: url,
            width: "320px",
            height: "240px",
            //btn: ['关闭'],
            //btnclass: ['btn btn-danger'],
            btn: null,
            callBack: function (iframeId) {
                //top.top.window.frames['FormShowSettSuccessDialog'].$.modalClose();
            }
        });
    }

</script>
